﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;

using System.Net;
using System.IO;
using System.Net.Sockets;
using System.Threading;

namespace Model
{
    public class Forbindelse
    {

        private NetworkStream _networkstream;
        private StreamWriter _streamWriter;
        public StreamReader StreamReader { get; private set; }

        private Socket _server;
        private readonly IPEndPoint _serveradr;


        public Forbindelse(int port, string adr)
        { 
            _serveradr = new IPEndPoint(IPAddress.Parse(adr), port);
        }


        public void Logon()
        {
            _server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _server.Connect(this._serveradr);

            _networkstream = new NetworkStream(this._server);
            StreamReader = new StreamReader(this._networkstream);
            _streamWriter = new StreamWriter(this._networkstream);

            
        }

        public void SendTilServer(string besked)
        {
            _streamWriter.WriteLine(besked);
            _streamWriter.Flush();
        }


        
    }
}
